/*
 * Copyright (c) 2018 Hitevision
 */

package tw.com.hitevision.whiteboard.android.render;

import android.content.Context;
import android.graphics.Color;

import androidx.annotation.ColorInt;
import tw.com.hitevision.whiteboard.android.Props;
import tw.com.hitevision.whiteboard.android.fastdraw.FastDraw;
import tw.com.hitevision.whiteboard.android.stateFile.HighlighterStateFile;
import tw.com.hitevision.whiteboard.android.widgets.HighlighterMenuView;

public class Highlighter extends Line {
    private static final int DEFAULT_ALPHA = 0x8f;
    private Context context;

    public Highlighter(Context context, float x, float y, float thickness) {
        super(context, x, y, thickness);
        this.context = context;
    }

    @Override
    public void setColor(@ColorInt int color) {
        final int a = Color.alpha(color);
        boolean now = true;
        int newAlpha = a;
        if (!FastDraw.isSupportedCanvasFastDraw() && Props.isPaintHelperEnabled() && FastDraw.isSupported() && !Props.getFlavorModel().equals(Props.Flavor.Model.Rs)) {
            if (a != 0xff) {
                newAlpha = 0xff;
            }
        } else {
            if (a != DEFAULT_ALPHA) {
                newAlpha = DEFAULT_ALPHA;
            }
        }

        if (newAlpha != a) {
            final int r = Color.red(color);
            final int g = Color.green(color);
            final int b = Color.blue(color);

            if (now){
                int alpha = HighlighterMenuView.seek_alpha;
                color = Color.argb(alpha, r, g, b);
            }

//            color = Color.argb(newAlpha, r, g, b);
        }

        super.setColor(color);
    }

    @Override
    public BaseItem copy() {
        Highlighter temp = new Highlighter(context, startX, startY, thickness);
        temp.clear();
        temp.path.set(getPath());

        for (int i = 0; i < points.size(); i++) {
            DiffPoint tempDP = new DiffPoint(points.get(i).x, points.get(i).y);
            tempDP.dx = points.get(i).dx;
            tempDP.dy = points.get(i).dy;
            temp.points.add(tempDP);
        }
        temp.x = x;
        temp.y = y;
        temp.width = width;
        temp.height = height;
        temp.detectRegion.set(detectRegion);
        temp.setColor(getColor());
//        temp.updateDetectRegion();
        temp.updatePathAgain = true;
        return temp;
    }

    public HighlighterStateFile getHighlighterStateFile() {
//        return new HighlighterStateFile(this, points, thickness, getId(), getFollowingStickynoteId());
        return new HighlighterStateFile(this, points, thickness, getId());
    }
}
